﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OracleClient;


namespace Userinterface_Ver._1_
{
    public partial class frmKhachHang : DevComponents.DotNetBar.Office2007Form
    {
        public static string makh;
        public frmKhachHang()
        {
            InitializeComponent();
        }

        private void frmKhachHang_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dataSet1.KHACH_HANG' table. You can move, or remove it, as needed.
       //     this.kHACH_HANGTableAdapter.Fill(this.dataSet1.KHACH_HANG);
            string sql = "select * from KHACH_HANG";
            OracleDataAdapter da = new OracleDataAdapter(sql,clsConnectDatabase.con);
            DataSet ds = new DataSet();
            da.Fill(ds,"KHACH_HANG");
            DataGridKH.DataSource = ds.Tables["KHACH_HANG"];
        }

        private void btnThemKH_Click(object sender, EventArgs e)
        {
            frmThemKH tkh = new frmThemKH();
            tkh.Show();
            this.Close();
        }

        private void btnSuaKH_Click(object sender, EventArgs e)
        {
            frmCapNhatKH cnkh = new frmCapNhatKH();
            cnkh.Show();
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void DataGridKH_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            makh = DataGridKH.CurrentCell.Value.ToString();
        }

        private void btnTimtheoma_Click(object sender, EventArgs e)
        {
          //  this.kHACH_HANGTableAdapter.Fill(this.dataSet1.KHACH_HANG);
            string sql = "select * from KHACH_HANG where MA_KH='" + txtTimtheoma.Text + "'";
            OracleDataAdapter da = new OracleDataAdapter(sql, clsConnectDatabase.con);
            DataSet ds = new DataSet();
            da.Fill(ds, "KHACH_HANG");
            DataGridKH.DataSource = ds.Tables["KHACH_HANG"];
        }

        private void btnTimtheoten_Click(object sender, EventArgs e)
        {
            try
            {
           //     this.kHACH_HANGTableAdapter.Fill(this.dataSet1.KHACH_HANG);
                string sql = "select * from KHACH_HANG where MA_KH='" + txtTimtheoma.Text + "'";
                OracleDataAdapter da = new OracleDataAdapter(sql, clsConnectDatabase.con);
                DataSet ds = new DataSet();
                da.Fill(ds, "KHACH_HANG");
                DataGridKH.DataSource = ds.Tables["KHACH_HANG"];
            }
            catch (Exception)
            {
                MessageBox.Show("khong tim thay","thong bao",MessageBoxButtons.OK);
            }
        }

        private void btnXoaKH_Click(object sender, EventArgs e)
        {
            try
            {
                string sql = "delete from KHACH_HANG where MA_KH='" + DataGridKH.CurrentCell.Value.ToString() + "'";
                OracleCommand com = new OracleCommand(sql, clsConnectDatabase.con);
                com.ExecuteNonQuery();
                this.Close();
                frmKhachHang kh = new frmKhachHang();
                kh.Show();
            }
            catch (OracleException ex)
            {
                MessageBox.Show(ex.Message,"thong bao");
            }
        }          
    }
}
